package com.ruoyi.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.admin.vo.MalfunctionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.admin.domain.Malfunction;
import com.ruoyi.admin.service.IMalfunctionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 故障信息Controller
 *
 * @author ruoyi
 * @date 2022-10-23
 */
@RestController
@RequestMapping("/malfunction")
public class MalfunctionController extends BaseController
{
    @Autowired
    private IMalfunctionService malfunctionService;

//    /**
//     * 查询故障信息列表
//     */
//    @RequiresPermissions("admin:malfunction:list")
//    @GetMapping("/list")
//    public TableDataInfo list(Malfunction malfunction)
//    {
//        startPage();
//        List<Malfunction> list = malfunctionService.selectMalfunctionList(malfunction);
//        return getDataTable(list);
//    }

    /**
     * 查询故障信息列表（故障信息首页展示）
     */
    @RequiresPermissions("admin:malfunction:list")
    @GetMapping("/list")
    public TableDataInfo list(Malfunction malfunction)
    {
        startPage();
        List<MalfunctionVo> list = malfunctionService.selectMalfunctionList2(malfunction);
        return getDataTable(list);
    }



    /**
     * 导出故障信息列表
     */
    @RequiresPermissions("admin:malfunction:export")
    @Log(title = "故障信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Malfunction malfunction)
    {
        List<Malfunction> list = malfunctionService.selectMalfunctionList(malfunction);
        ExcelUtil<Malfunction> util = new ExcelUtil<Malfunction>(Malfunction.class);
        util.exportExcel(response, list, "故障信息数据");
    }

    /**
     * 获取故障信息详细信息
     */
    @RequiresPermissions("admin:malfunction:query")
    @GetMapping(value = "/{malfunctionId}")
    public AjaxResult getInfo(@PathVariable("malfunctionId") Long malfunctionId)
    {
        return AjaxResult.success(malfunctionService.selectMalfunctionByMalfunctionId2(malfunctionId));
    }

    /**
     * 新增故障信息
     */
    @RequiresPermissions("admin:malfunction:add")
    @Log(title = "故障信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Malfunction malfunction)
    {
        return toAjax(malfunctionService.insertMalfunction(malfunction));
    }

    /**
     * 修改故障信息
     */
    @RequiresPermissions("admin:malfunction:edit")
    @Log(title = "故障信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Malfunction malfunction)
    {
        return toAjax(malfunctionService.updateMalfunction(malfunction));
    }

    /**
     * 删除故障信息
     */
    @RequiresPermissions("admin:malfunction:remove")
    @Log(title = "故障信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{malfunctionIds}")
    public AjaxResult remove(@PathVariable Long[] malfunctionIds)
    {
        return toAjax(malfunctionService.deleteMalfunctionByMalfunctionIds(malfunctionIds));
    }
}
